package com.yixun.qfbao.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

public class CalculateUtil {
    public static String signRate(String total,String sign){
        DecimalFormat df = new DecimalFormat("0.00");
        try{
            BigDecimal t = BigDecimal.valueOf(Long.valueOf(total.toString()));
            BigDecimal s = BigDecimal.valueOf(Long.valueOf(sign.toString()));
            if(t.compareTo(BigDecimal.ZERO) == 0){
                return "0.00%";
            }
            return  df.format(s.divide(t,4, RoundingMode.HALF_DOWN).multiply(BigDecimal.valueOf(100L)).stripTrailingZeros()) + "%";

        }catch (Exception e){
            return "0.00%";
        }
    }
}
